import request from '@/utils/request'
import logger from '@/utils/logger'

/**
 * 获取操作日志列表
 * @param {Object} data - 查询参数
 * @returns {Promise} API响应
 */
export const fetchLogList = async (data) => {
  try {
    const response = await request({
      url: '/dealer/pzDealerOptlog/getPzDealerOptlogPageListByDealerId',
      method: 'post',
      data,
    })
    return response
  } catch (error) {
    logger.error('获取操作日志列表失败', error)
    throw error
  }
}

/**
 * @description 退出登录
 */
export const logout = async () => {
  try {
    const response = await request({
      url: '/dealerLogout',
      method: 'post',
    })
    return response
  } catch (error) {
    logger.error('退出登录失败', error)
    throw error
  }
}

/**
 * @description 获取个人信息
 */
export const getUserInfo = async () => {
  try {
    const response = await request({
      url: '/dealer/pzDealer/viewSelfDealer',
      method: 'post',
    })
    return response
  } catch (error) {
    logger.error('获取个人信息失败', error)
    throw error
  }
}

/**
 * @description 保存个人信息
 */
export const saveUserInfo = async (data) => {
  try {
    const response = await request({
      url: '/dealer/pzDealer/updateSelfDealer',
      method: 'post',
      data,
    })
    return response
  } catch (error) {
    logger.error('保存个人信息失败', error)
    throw error
  }
}
